﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.utils {
    import flash.display.*;
    import flash.geom.*;

    public class Displays {

        public static function getChild(_arg1:DisplayObjectContainer, _arg2:String):DisplayObject{
            var _local3:Array = _arg2.split("/");
            var _local4:String = _local3.shift();
            var _local5:DisplayObject = _arg1.getChildByName(_local4);
            if (((_local3.length) && ((_local5 is DisplayObjectContainer)))){
                _local5 = getChild((_local5 as DisplayObjectContainer), _local3.join("/"));
            };
            return (_local5);
        }
        public static function findChild(_arg1:DisplayObjectContainer, _arg2:String):DisplayObject{
            var _local3:DisplayObject;
            var _local4:int;
            while (_local4 < _arg1.numChildren) {
                _local3 = _arg1.getChildAt(_local4);
                if (!_local3){
                    break;
                } else {
                    if (_local3.name == _arg2){
                        return (_local3);
                    };
                    if ((_local3 is DisplayObjectContainer)){
                        _local3 = findChild(DisplayObjectContainer(_local3), _arg2);
                        if (_local3){
                            return (_local3);
                        };
                    };
                };
                _local4++;
            };
            return (null);
        }
        public static function showChilds(_arg1:DisplayObjectContainer, _arg2:String=""):void{
            var _local3:DisplayObject;
            var _local4:int;
            while (_local4 < _arg1.numChildren) {
                _local3 = _arg1.getChildAt(_local4);
                l("NAME", ((_arg2 + "/") + _local3.name));
                if ((_local3 is DisplayObjectContainer)){
                    showChilds(DisplayObjectContainer(_local3), ((_arg2 + "/") + _local3.name));
                };
                _local4++;
            };
        }
        public static function removeAllChildren(_arg1:DisplayObjectContainer):void{
            if (_arg1){
                while (_arg1.numChildren) {
                    _arg1.removeChildAt(0);
                };
            };
        }
        public static function removeChild(_arg1:DisplayObject):void{
            if (((_arg1) && (_arg1.parent))){
                _arg1.parent.removeChild(_arg1);
            };
        }
        public static function getChildren(_arg1:DisplayObjectContainer):Array{
            var _local2:Array = [];
            var _local3:int = _arg1.numChildren;
            var _local4:int;
            while (_local4 < _local3) {
                _local2.push(_arg1.getChildAt(_local4));
                _local4++;
            };
            return (_local2);
        }
        public static function setIndices(_arg1:Array):void{
            var _local2:int = _arg1.length;
            var _local3:int;
            while (_local3 < _local2) {
                setIndex(DisplayObject(_arg1[_local3]), _local3);
                _local3++;
            };
        }
        public static function setIndex(_arg1:DisplayObject, _arg2:int=-1):void{
            if (_arg1.parent){
                if (_arg2 == -1){
                    _arg2 = (_arg1.parent.numChildren - 1);
                };
                _arg1.parent.setChildIndex(_arg1, _arg2);
            };
        }
        public static function removeChildByName(_arg1:DisplayObjectContainer, _arg2:String):DisplayObject{
            var _local3:DisplayObject = _arg1.getChildByName(_arg2);
            if (_local3){
                _arg1.removeChild(_local3);
            };
            return (_local3);
        }
        public static function replaceChild(_arg1:DisplayObject, _arg2:DisplayObject):void{
            var _local4:int;
            var _local3:DisplayObjectContainer = _arg1.parent;
            if (_local3){
                _local4 = _local3.getChildIndex(_arg1);
                removeChild(_arg1);
                _local3.addChildAt(_arg2, _local4);
            };
        }
        public static function correctScaling(_arg1:DisplayObjectContainer, _arg2:DisplayObject, _arg3:Number, _arg4:Number, _arg5:int=0, _arg6:int=0):void{
            Displays.correctRegPoint(_arg2, _arg5, _arg6);
            _arg1.scaleX = (_arg1.scaleY = Numbers.scaleWithinRect(_arg2.width, _arg2.height, _arg3, _arg4));
        }
        private static function getRegPoint(_arg1:DisplayObject, _arg2:int=0, _arg3:int=0):Point{
            var _local4:Rectangle = _arg1.getRect(_arg1);
            var _local5:Number = (_local4.width / 2);
            var _local6:Number = (_local4.height / 2);
            var _local7:Number = (_local4.x + _local5);
            var _local8:Number = (_local4.y + _local6);
            var _local9:Point = new Point((-(_local7) + (_local5 * -(_arg2))), (-(_local8) + (_local6 * -(_arg3))));
            return (_local9);
        }
        private static function correctRegPoint(_arg1:DisplayObject, _arg2:int=0, _arg3:int=0):void{
            var _local4:Point = Displays.getRegPoint(_arg1, _arg2, _arg3);
            _arg1.x = _local4.x;
            _arg1.y = _local4.y;
        }

    }
}//package net.wooga.pets.utils 
